import java.io.*;
import java.util.*;

class crypto_01 {

static char [] base64_symbol =
    {
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
        'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
        'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
        'w', 'x', 'y', 'z', '0', '1', '2', '3',
        '4', '5', '6', '7', '8', '9', '*', '/'
    };

    private static int hex2dec(char hex) {
        if ('0' <= hex && hex <= '9') {
            return (hex - '0');
        } else if (hex >= 'A' && hex <= 'Z') {
            return (hex - 'A'  + 10);
        }

        return (hex - 'a' + 10);
    }

    private static String readplaintext(String file) throws IOException {
        FileReader fr = null;
        String line = null;

        try {
            fr = new FileReader (file);
            System.out.println("Input file: " + file);
        } catch(FileNotFoundException e) {
            System.out.println("Unable to open file:" + file);
            System.out.println("ERROR = " + e.getMessage());
        }

        BufferedReader reader = new BufferedReader(fr);

        while (reader.ready())
            line = reader.readLine();

        reader.close();
        return (line);
    }

    public static void main(String[] args) throws IOException {
        String s = args[0];
        String plaintext = null;
        StringBuilder ciphertext = new StringBuilder();
        int value;
        plaintext = readplaintext(s);
        System.out.println("Plaintext: " + plaintext);
        for(int count = plaintext.length()-1; count > 0;) {
            value = 0;
            value = hex2dec (plaintext.charAt(count--));
            value += (hex2dec (plaintext.charAt(count--)) * 16);
            value += (hex2dec (plaintext.charAt(count--)) * 16 * 16);
            int rem = value % 64;
            ciphertext.insert(0, base64_symbol[rem]);
            int div = (value - rem) / 64;
            ciphertext.insert(0, base64_symbol[div]);
        }
        System.out.println( "Ciphertext: " + ciphertext);
    }
}
